package com.zzl.bonds.ticket.manager;

import com.zzl.bonds.ticket.feign.UserFeign;
import com.zzl.bonds.ticket.service.common.SendMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author ：hyt
 * @description：处理发送消息
 * @date ：2022/1/10 14:50
 */
@Component
public class SendMessageManager {
    @Autowired
    private UserFeign userFeign;

    @Autowired
    private SendMsgService sendMsgService;

//    /**
//     * 发送操作类消息,给拥有按钮权限的人
//     *
//     * @param buttonAction 按钮标识
//     * @param msgContent   消息内容
//     * @param user         登录用户
//     * @throws SysException 业务异常
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public void sendTransferOperateMsg(TicketransferEntity ticketransferEntity, String buttonAction, String msgContent, User user) throws SysException {
//        //发送人的用户id集合
//        List<Integer> userIds = userFeign.getUserIdListByButtonAction(buttonAction, user.getEnterpriseId());
//        if (!CollectionUtils.isEmpty(userIds)) {
//            String msg  = msgContent.
//                    replace(SIGN_ENTERPRISE, ticketransferEntity.getReceiveEnterpriseName()).
//                    replace(TRANSFER_ENTERPRISE, ticketransferEntity.getTransferEnterpriseName()).
//                    replace(APPLICANT_KEY, user.getUsername()).
//                    replace(TICKET_AMOUNT_KEY, NumberUtil.numberFormatString(ticketransferEntity.getTransferAmount()));
//            sendMsgService.sendMsgToMq(MsgCategoryEnum.MSG_CATEGORY_OPRATE.getCode(), msg, userIds, user, new ArrayList<>());
//        }
//    }
//
//    /**
//     * 发送操作类消息,给指定企业
//     *
//     * @param buttonAction 按钮标识
//     * @param msgContent   消息内容
//     * @param user         用户
//     * @param enterpriseId 指定企业
//     * @throws SysException 业务异常
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public void sendTransferOperateMsg(TicketransferEntity ticketransferEntity, String buttonAction, String msgContent, User user, String enterpriseId) throws SysException {
//        //发送人的用户id集合
//        List<Integer> userIds = userFeign.getUserIdListByButtonAction(buttonAction, enterpriseId);
//        if (!CollectionUtils.isEmpty(userIds)) {
//            String msg  =msgContent.
//                    replace(SIGN_ENTERPRISE, ticketransferEntity.getReceiveEnterpriseName()).
//                    replace(TRANSFER_ENTERPRISE, ticketransferEntity.getTransferEnterpriseName()).
//                    replace(APPLICANT_KEY, user.getUsername()).
//                    replace(TICKET_AMOUNT_KEY, NumberUtil.numberFormatString(ticketransferEntity.getTransferAmount()));
//            sendMsgService.sendMsgToMq(MsgCategoryEnum.MSG_CATEGORY_OPRATE.getCode(), msg, userIds, user, new ArrayList<>());
//        }
//    }
//
//    /**
//     * 发送消息类消息，给指定用户集合
//     *
//     * @param userIdList 消息接收用户集合
//     * @param msgContent 消息内容
//     * @param user       登录用户
//     * @throws SysException 业务异常
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public void sendTransferOrdinaryMsg(TicketransferEntity ticketransferEntity, String msgContent, List<Integer> userIdList, User user) throws SysException {
//        //消息处理
//        String msg  =  msgContent.
//                replace(SIGN_ENTERPRISE, ticketransferEntity.getReceiveEnterpriseName()).
//                replace(TRANSFER_ENTERPRISE, ticketransferEntity.getTransferEnterpriseName()).
//                replace(APPLICANT_KEY, user.getUsername()).
//                replace(TICKET_AMOUNT_KEY, NumberUtil.numberFormatString(ticketransferEntity.getTransferAmount()));
//        sendMsgService.sendMsgToMq(MsgCategoryEnum.MSG_CATEGORY_ORDINARY.getCode(), msg, userIdList, user, new ArrayList<>());
//    }
//
//    /**
//     * 或者 开立票据的信息
//     *
//     * @param businessNo
//     * @param businessMsg
//     * @return
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public String getTicketOpenMsg(Integer businessNo, BusinessMsg businessMsg) {
//        switch (businessNo) {
//            case 1:
//                return getMsg(businessMsg, TICKET_OPEN_SUBMIT_MSG);
//            case 2:
//                return getMsg(businessMsg, TICKET_OPEN_REVIEW_PASS_MSG);
//            case 3:
//                return getMsg(businessMsg, TICKET_OPEN_REVIEW_PASS_PLATFORM_MSG);
//            case 4:
//                return getMsg(businessMsg, TICKET_OPEN_REVIEW_REJECT_MSG);
//            case 5:
//                return getMsg(businessMsg, TICKET_OPEN_APPROVE_PASS_MSG);
//            case 6:
//                return getMsg(businessMsg, TICKET_OPEN_APPROVE_PASS_PLATFORM_SIGN_MSG);
//            case 7:
//                return getMsg(businessMsg, TICKET_OPEN_APPROVE_REJECT_PLATFORM_SIGN_MSG);
//            case 8:
//                return getMsg(businessMsg, TICKET_OPEN_SIGN_PASS_MSG);
//            case 9:
//                return getMsg(businessMsg, TICKET_OPEN_SIGN_REJECT_MSG);
//            default:
//                return "";
//        }
//    }
//
//    private String getMsg(BusinessMsg businessMsg, String msgContent) {
//        if (ObjectUtils.isEmpty(businessMsg.getApplicantUserName())) {
//            businessMsg.setApplicantUserName("");
//        }
//        return msgContent.
//                replace(SIGN_ENTERPRISE, businessMsg.getReceiveEnterpriseName()).
//                replace(OPEN_ENTERPRISE, businessMsg.getOpenEnterpriseName()).
//                replace(APPLICANT_KEY, businessMsg.getApplicantUserName()).
//                replace(TICKET_AMOUNT_KEY, NumberUtil.numberFormatString(businessMsg.getTicketAmount()));
//    }
}
